Utilities for parsing Character Separated Value files (CSV)
Copyright (C) 2002 Alex Mottram (geo_alexm at cox-internet.com)
+ Copyright (C) 2002-2005 Robert Lipe
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
xcsv_file.epilogue_lines++;
}
+static
+time_t
+yyyymmdd_to_time(const char *s)
+{
+ int t = atol(s);
+ struct tm tm;
+
+ memset(&tm, 0, sizeof(tm));
+
+ tm.tm_mday = t % 100;
+ t = t / 100;
+ tm.tm_mon = t % 100 - 1;
+ t = t / 100;
+ tm.tm_year = t - 1900;
+ return mktime(&tm);
+}
+
+static
+long
+time_to_yyyymmdd(time_t t)
+{
+ long b;
+ struct tm *tm = gmtime(&t);
+
+ b = (1900 + tm->tm_year) * 10000 +
+ (1 + tm->tm_mon) * 100 +
+ tm->tm_mday;
+
+ return b;
+}
+
/*****************************************************************************/
/* xcsv_parse_val() - parse incoming data into the waypt structure. */
/* usage: xcsv_parse_val("-123.34", *waypt, *field_map) */
/* Time as time_t */
wpt->creation_time = atol(s);
} else
+ if (strcmp(fmp->key, "YYYYMMDD_TIME") == 0) {
+ wpt->creation_time = yyyymmdd_to_time(s);
+ } else
+ if (strcmp(fmp->key, "GEOCACHE_LAST_FOUND") == 0) {
+ wpt->gc_data.last_found = yyyymmdd_to_time(s);
+ } else
/* GEOCACHING STUFF ***************************************************/
if (strcmp(fmp->key, "GEOCACHE_DIFF") == 0) {
if (strcmp(fmp->key, "GEOCACHE_CONTAINER") == 0) {
wpt->gc_data.container = gs_mkcont(s);
} else
+ if (strcmp(fmp->key, "GEOCACHE_HINT") == 0) {
+ wpt->gc_data.hint = csv_stringtrim(s, "", 0);
+ } else
+ if (strcmp(fmp->key, "GEOCACHE_PLACER") == 0) {
+ wpt->gc_data.placer = csv_stringtrim(s, "", 0);
+ } else
+
+ /* OTHER STUFF ***************************************************/
if ( strcmp( fmp->key, "PATH_DISTANCE_MILES") == 0) {
/* Ignored on input */
} else
/* time as a time_t variable */
sprintf(buff, fmp->printfc, wpt->creation_time);
} else
+ if (strcmp(fmp->key, "YYYYMMDD_TIME") == 0) {
+ sprintf(buff, fmp->printfc, time_to_yyyymmdd(wpt->creation_time));
+ } else
+ if (strcmp(fmp->key, "GEOCACHE_LAST_FOUND") == 0) {
+ sprintf(buff, fmp->printfc, time_to_yyyymmdd(wpt->gc_data.last_found));
+ } else
/* GEOCACHE STUFF **************************************************/
if (strcmp(fmp->key, "GEOCACHE_DIFF") == 0) {
if (strcmp(fmp->key, "GEOCACHE_TYPE") == 0) {
/* Geocache Type */
sprintf(buff, fmp->printfc, gs_get_cachetype(wpt->gc_data.type));
+ } else
+ if (strcmp(fmp->key, "GEOCACHE_HINT") == 0) {
+ sprintf(buff, fmp->printfc, NONULL(wpt->gc_data.hint));
+ } else
+ if (strcmp(fmp->key, "GEOCACHE_PLACER") == 0) {
+ sprintf(buff, fmp->printfc, NONULL(wpt->gc_data.placer));
} else {
/* this should probably never happen */
}
example: IFIELD TIMET_TIME,"","%ld"
+ o YYYYMMDD_TIME
+ TIMET_TIME is the waypoint's creation time, if any. It's a single
+ decimal field containing four digits of year, two digits of month,
+ and two digits of date. Internally it is a LONG INTEGER and thus
+ requires a LONG INTEGER printf conversion.
+
+ example: IFIELD YYYYMMDD_TIME,"","%ld"
+
o GEOCACHE_DIFF
GEOCACHE_DIFF is valid only for geocaches and represents a DOUBLE
PRECISION FLOAT. A "three and a half star" cache would therefore be "3.5"
example: GEOCACHE_TYPE,"","%s"
+ o GEOCACHE_PLACER
+ GEOCACHE_PLACER is a string containing the name of the placer of a
+ geocache.
+
+ example: GEOCACHE_PLACER,"","%s"
+
+ o GEOCACHE_LAST_FOUND
+ A long integer in format YYYYMMDD containing the last time this geocache
+ was found.
+
+ example: GEOCACHE_LAST_FOUND,"","%ld"
+
+ o GEOCACHE_HINT
+ The hint for this geocache. No additional transformation (such as rot13)
+ will be performed on this string.
+
+ example: GEOCACHE_HINT,"","%s"
+
o PATH_DISTANCE_MILES
PATH_DISTANCE_MILES outputs the total length of the route or track from
the start point to the current point, in miles. This and the altitude